# 计算力学结果
import math
from typing import List

from seaman.core import Validator

from algs.common import OilWellData
from common.params import SoftParams
# class CasingParams:
#     # 开始深度
#     start: float
#     # 结束深度
#     end: float
#     # 套管内径
#     d: float
#     # 摩擦系数
#     mu_pull: float
#     mu_push: float


class ForceResult:
    depth: float
    force: float
    low_weak_force: float
    high_weak_force: float
    # 70%
    seventy_force: float


class UniForceResult:
    # 深度
    depth: float
    # 张力
    F_pull: float
    F_push: float
    # F h
    F_weak_high: float
    # F l
    F_weak_low: float
    # F 70
    F_weak_rate_low: float
    # 正压力
    N_pull: float
    N_push: float
    # N h
    N_weak_high: float
    # N l
    N_weak_low: float
    # N 70%
    N_weak_rate_low: float
    # 压力求和
    N_sum: float
    # 下放时电缆电缆极限下入深度
    push_cable_pressure: float
    # 轴力开始小于0的点
    pressure_high_depth: float
    # 轴力结束小于0的点
    pressure_low_depth: float
    # 计算一个Q值 就是最适合的那个值
    Q_final: float
    # 上提液体阻力
    pull_fluid_res: float
    # 下放液体阻力
    push_fluid_res: float

# 计算力学结果
class AverageResult:
    depth: float
    inclination_average: float


# 计算参数
class AxialForceResult:
    # 测井深度
    depth: float
    # 倾斜角
    inclination: float
    # 井斜角变化率
    inclination_rate: float
    # 方位角
    azimuth: float
    # 方位角变化率
    azimuth_rate: float
    # # 狗腿度
    dog_leg_severity: float
    # 弯矩
    bending_moment: float
    #########################################
    # 条件绘图参数
    # 正压力 默认的 pull
    N_pull: float
    # push 时候的正压力
    N_push: float
    # N h
    N_weak_high: float
    # N l
    N_weak_low: float
    # N 70%
    N_weak_rate_low: float


    # 张力 默认的 pull
    F_pull: float
    # push 时候的张力
    F_push: float
    # F h
    F_weak_high: float
    # F l
    F_weak_low: float
    # F 70
    F_weak_rate_low: float


    F: float
    N: float
    # 下放的流体阻力
    push_fluid: float
    # 上提的流体阻力
    pull_fluid: float



# 公共函数
# 数据初始化
def data_init(_list_: List[OilWellData]) -> List[AxialForceResult]:
    result_arr: List[AxialForceResult] = []
    for item in _list_:
        t: AxialForceResult = AxialForceResult()
        t.depth = item.depth
        t.inclination = item.inclination
        t.azimuth = item.azimuth
        t.dog_leg_severity = item.dog_leg_severity
        t.inclination_rate = math.radians(item.inclination_rate) / 30
        t.azimuth_rate = math.radians(item.azimuth_rate) / 30
        result_arr.append(t)
    return result_arr




def get_instrument_area(params: SoftParams) -> float:
    return math.pi * 0.25 * math.pow(params.d1, 2)


# 测井仪器的单位密度
def get_instrument_uint_density(params: SoftParams) -> float:
    return params.m1 / get_instrument_area(params)


# 测井仪器的单位浮重
def get_instrument_unit_weight(params: SoftParams) -> float:
    return (get_instrument_uint_density(params) - params.rou_m) * get_instrument_area(params) * 9.81


# 电缆截面面积
def get_cable_area(params: SoftParams) -> float:
    return math.pi * 0.25 * math.pow(params.d2, 2)


# 电缆的单位密度
def get_cable_uint_density(params: SoftParams) -> float:
    return params.m2 / get_cable_area(params)


# 电缆的单位浮重
def get_cable_unit_weight(params: SoftParams) -> float:
    return (get_cable_uint_density(params) - params.rou_m) * get_cable_area(params) * 9.81
